package com.hundsun.cprs.yyt.service.form.service.impl;

import java.util.List;

import com.hundsun.cprs.yyt.service.form.dao.FormDao;
import com.hundsun.cprs.yyt.service.form.domain.Form;
import com.hundsun.cprs.yyt.service.form.dto.FormAttrInfo;
import com.hundsun.cprs.yyt.service.form.dto.FormInfo;
import com.hundsun.cprs.yyt.service.form.service.FormService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import com.hundsun.cprs.yyt.common.base.BaseService;
import com.hundsun.cprs.yyt.service.form.dao.FormAttrDao;
import com.hundsun.cprs.yyt.service.form.dao.FormDao;
import com.hundsun.cprs.yyt.service.form.domain.Form;
import com.hundsun.cprs.yyt.service.form.dto.FormAttrInfo;
import com.hundsun.cprs.yyt.service.form.dto.FormInfo;
import com.hundsun.cprs.yyt.service.form.service.FormService;

@Service
public class FormServiceImpl extends BaseService implements FormService {

    @Autowired
    private FormDao formDao;
    @Autowired
    private FormAttrDao formAttrDao;

    @Override
    public Form getFormByFormCode(String formCode) {
        return formDao.selectByFormCode(formCode);
    }

    @Override
    @Cacheable(value="FormInfoCache:formCode",key="#formCode")
    public FormInfo getFormInfoByFormCode(String formCode) {
        FormInfo form = formDao.selectByFormCode(formCode);

        //加载表单模板的关联属性
        List<FormAttrInfo> formAttrList = formAttrDao.selectFormAttrInfoByFormId(form.getId());
        form.setFormAttrInfoList(formAttrList);
        return form;
    }

    @Override
    public void createForm(Form form) {
        //TODO:延迟实现
    }

    @Override
    @CacheEvict(value="FormInfoCache:formCode",key="#from.formCode")
    public void modifyForm(Form form) {
        //TODO:延迟实现
    }

    @Override
    public Form deleteFormById(Long id) {
        //TODO:延迟实现
        return null;
    }

}
